package battle

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

type Server struct {
	Engine *gin.Engine
	Host   string
	Port   int
}

// New
// 构建服务对象
func New(host string, port int) *Server {
	return &Server{
		Engine: gin.Default(),
		Host:   host,
		Port:   port,
	}
}

// Run
// 运行服务
func (p *Server) Run() error {
	if p.Host == "" {
		p.Host = "0.0.0.0"
	}

	if p.Port == 0 {
		p.Port = 8080
	}

	return p.Engine.Run(fmt.Sprintf("%s:%d", p.Host, p.Port))
}
